#include "dialog.h"
#include "ui_dialog.h"


Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);

    connect(ui->radioButtonBlack, SIGNAL(clicked()), this, SLOT(do_setFontColor()));
    connect(ui->radioButtonRed, SIGNAL(clicked()), this, SLOT(do_setFontColor()));
    connect(ui->radioButtonBlue, SIGNAL(clicked()), this, SLOT(do_setFontColor()));

}

Dialog::~Dialog()
{
    if (ui) {
        delete ui;
        ui = nullptr;
    }
}

void Dialog::do_setFontColor()
{
    QPalette plet = ui->plainTextEdit->palette();
    if (ui->radioButtonBlack->isChecked()) {
        plet.setColor(QPalette::Text, Qt::black);
    } else if (ui->radioButtonRed->isChecked()) {
        plet.setColor(QPalette::Text, Qt::red);
    } else if (ui->radioButtonBlue->isChecked()) {
        plet.setColor(QPalette::Text, Qt::blue);
    } else {
        plet.setColor(QPalette::Text, Qt::black);
    }

    ui->plainTextEdit->setPalette(plet);
}

void Dialog::on_btnErase_clicked(bool checked)
{
    ui->plainTextEdit->clear();
}

void Dialog::on_checkBoxUnder_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();
    font.setUnderline(checked);
    ui->plainTextEdit->setFont(font);
}

void Dialog::on_checkBoxItalic_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();
    font.setItalic(checked);
    ui->plainTextEdit->setFont(font);
}

void Dialog::on_checkBoxBold_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();
    font.setBold(checked);
    ui->plainTextEdit->setFont(font);
}

